package com.loan.system.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.loan.system.domain.ApplyEntity;
import com.loan.system.domain.OverLogEntity;
import com.loan.system.mapper.OverLogMapper;
import com.loan.system.service.OverLogService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.Date;

/**
 * @author shiguang
 * @date 2022年09月24日 18:48
 */
@Service
@RequiredArgsConstructor
public class OverLogServiceImpl implements OverLogService {

    private final OverLogMapper overLogMapper;

    @Override
    public void save(ApplyEntity entity, Integer money) {
        OverLogEntity overLog = new OverLogEntity();
        overLog.setApplyId(entity.getId());
        overLog.setCompanyId(entity.getCompanyId());
        overLog.setUserId(entity.getUserId());
        overLog.setOverDay(entity.getOverDay());
        overLog.setOverMoney(money);
        overLog.setCreateTime(new Date());
        overLogMapper.insert(overLog);
    }

    @Override
    public long selectCountByUserIdAndCompanyId(Long userId, Long companyId) {
        return overLogMapper.selectCount(new QueryWrapper<OverLogEntity>().eq("user_id", userId).eq("company_id", companyId));
    }
}
